package com.mall.commons.exception;

import com.mall.commons.utils.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@Slf4j
@RestControllerAdvice(annotations = {RestController.class,Controller.class})
public class GlobalExceptionHandler {


    /**
     * 自定义业务异常捕获处理
     * @param ex
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public CommonResult<String> exceptionHandler(BusinessException ex) {
        String exMessage = ex.getMessage();
        log.error(exMessage);
        return CommonResult.error(exMessage);
    }
}
